<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>抽签结果录入</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            strong{
                color:#ffbc00;
            }
            u {
                color:#f00;
            }

            body {
                font-family: 'Sans', sans-serif;
                line-height: 30px;
                background:url('assets/img/background12.jpg')no-repeat;
                background-size:cover;
            }
            .parent{
                position:relative;
                left:50%;
                width:1050px;
                margin-left:-525px;
                margin-top:10px;
                display: flex;
                text-align: center;
            }
            .alp-div {
                filter:alpha(Opacity=90);
                -moz-opacity:0.8;
                opacity: 0.7;
                background-color: #2B2B2B;
                color:#fff;
                position:relative;
                width:1600px;
                left:50%;
                padding: 20px;
                margin-left:-800px;
                margin-top:90px;
                border:1px solid #fff;
                text-align: center;

            }
            .admin{
                position:relative;
                left:50%;
                width:224px;
                margin-left:-112px;
                font-size: 16px;
                margin-top:10px;
                margin-bottom:20px;
            }
            .div1{

            }
            .div2{
            }
            .div3{
                margin-left: 50px;
            }
            .table1{
                margin: 0 auto;
            }
            .table2{
                width: 500px;
                height: 410px;
            }
            .table3{
                width: 500px;
                height: 410px;
            }
            .judge{
                position:relative;
                left:50%;
                width:900px;
                margin-left:-450px;

            }
            .score{
                position:relative;
                left:50%;
                width:634px;
                margin-left:-317px;

            }
            .question{
                position:relative;
                left:50%;
                width:863px;
                margin-left:-431px;
                height: 500px;
            }
            .button-center {
                margin-top: 0px;
                text-align:center;
            }
            .btn {
                width: 240px;
                height: 60px;
                font-size: 20px;
            }
            button:hover{
                color: #2945a5;
            }
            .form-text-center{
                text-align: center;
                font-size: 20px;
            }
        </style>
    </head>
    <body>
        <?PHP
        $school_arr=['哈尔滨工业大学（深圳）','华南理工大学','华中科技大学','华中师范大学','暨南大学','南方科技大学','武汉大学','湘潭大学','中南大学','中山大学'];



        $mysqli = mysqli_init();
        $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); //设置超时时间
        $mysqli->real_connect('127.0.0.1', 'root', 'mysql');
        $sql = "CREATE DATABASE IF NOT EXISTS CUPT DEFAULT CHARSET utf8 COLLATE utf8_general_ci;";
        if ($mysqli->query($sql) == TRUE) {
        //printf("Table CUPT successfully created.\n");
        }
        mysqli_select_db($mysqli,"CUPT");
        $sql = "CREATE TABLE IF NOT EXISTS `judge` (
        `id` varchar(20) DEFAULT NULL,
        `password` varchar(30) DEFAULT NULL,
        `name` varchar(20) DEFAULT NULL,
        `sex` varchar(4) DEFAULT NULL,
        `school` varchar(40) DEFAULT NULL,
        `school_position` varchar(20) DEFAULT NULL,
        `phone_number` varchar(20) DEFAULT NULL,
        `chairman_qualifications` varchar(3) DEFAULT NULL,
        `email` varchar(20) DEFAULT NULL,
        `bank_account` varchar(30) DEFAULT NULL,
        `bank` varchar(40) DEFAULT NULL,
        `clothing_model` varchar(10) DEFAULT NULL,
        UNIQUE KEY(`email`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        if (mysqli_query($mysqli, $sql)) {
        //echo "数据表 judge 创建成功";
        } else {
        //echo "创建数据表错误: " . mysqli_error($mysqli);
        }


        for($i=0;$i<=9;$i++){//取出学校中评委姓名
        $sql="select name from judge where `school`='$school_arr[$i]';";
        $rst=$mysqli->query($sql);
        $j=0;
        while ($row = mysqli_fetch_assoc($rst)) {
        $name[$i][$j] = $row['name'];
        $j++;
        }
        }









        if(!empty($_GET['email'])){$email=$_GET['email'];}else{$email='';}
        $site_arr=range(1,10);

        for($i=0,$string1='',$string2='',$string2_1='',$string2_2='';$i<=9;$i++)
        {  
        $j=$i+1;

        $sql="select school_number from school_information_list where `school`='$school_arr[$i]'";
        $rst=$mysqli->query($sql);
        while ($row = mysqli_fetch_assoc($rst)) {
        $school_number[$i] = $row['school_number'];
        }


        $string1=$string1."<th>".$school_arr[$i]."</th>";
        $string2=$string2."<td><input type='number' class='form-control' id='school_number_$j' name='school_number_$j' oninput='if(value>10)value=10;if(value<1)value=1' placeholder='抽签号' value='$school_number[$i]' onkeyup='repeat()'></td>";

        if(!empty($name[$i][0])){
        $string2_1=$string2_1."<td>".(string)$name[$i][0]."</td>";
        }else{
        $string2_1=$string2_1."<td></td>";
        }
        if(!empty($name[$i][1])){
        $string2_2=$string2_2."<td>".(string)$name[$i][1]."</td>";
        }else{
        $string2_2=$string2_2."<td></td>";
        }


        }
        $string1="<tr><th>学校</th>".$string1."<tr>";
        $string2="<tr><th>抽签号</th>".$string2."<tr>";
        $string2_1="<tr><th>评委a</th>".$string2_1."<tr>";
        $string2_2="<tr><th>评委b</th>".$string2_2."<tr>";

        $site_arr = array
        (
        array(5,6,7,1,2,3,8,9,10,4),
        array(4,5,6,2,3,1,9,10,8,7),
        array(5,6,4,3,1,2,7,8,9,10),
        array(6,4,5,10,1,2,8,9,7,3),
        array(3,4,5,1,2,10,9,7,8,6),
        array(4,5,3,2,10,1,6,7,8,9),
        array(5,3,4,9,10,1,7,8,6,2),
        array(2,3,4,10,1,9,8,6,7,5),
        array(3,4,2,1,9,10,6,7,5,8),
        array(4,2,3,10,8,9,7,5,6,1)
        );
        $self_choose_session_site=array//正方自选题目的场次和场地号
        (
        array(3,2),
        array(4,1),
        array(5,3),
        array(6,2),
        array(7,1),
        array(8,3),
        array(9,2),
        array(10,1),
        array(10,2),
        array(10,3),
        );
        $judge_arr_A=array
        (
        array('1a','1a','2a','3a','9b','10a'),
        array('10a','1a','2a','8b','9b','10a'),
        array('10a','1a','2a','8b','9b','10a'),
        array('10a','1a','2a','8b','9b','10a'),
        array('9a','1a','7b','8b','9a','10b'),
        array('9a','1a','7b','8b','9a','10b'),
        array('9a','1a','7b','8b','9a','10b'),
        array('8a','6a','7b','8a','9a','10b'),
        array('8a','6a','7b','8a','9a','10b'),
        array('8a','6a','7b','8a','9a','10b')
        );

        $judge_arr_B=array
        (
        array('7a','5a','6a','7a','8a','9a'),
        array('7a','5a','6a','7a','8a','9a'),
        array('7a','5a','6a','7a','8a','9a'),
        array('6a','4b','5a','6a','7a','8a'),
        array('6a','4b','5a','6a','7a','8a'),
        array('6a','4b','5a','6a','7a','8a'),
        array('5a','3b','4b','5a','6b','7a'),
        array('5a','3b','4b','5a','6b','7a'),
        array('5a','3b','4b','5a','6b','7a'),
        array('4a','2b','3b','4a','5b','6b')
        );

        $judge_arr_C=array
        (
        array('4a','2b','3b','4a','5b','6b'),
        array('4a','2b','3b','4a','5b','6b'),
        array('3a','1b','2b','3a','4a','5b'),
        array('3a','1b','2b','3a','4a','5b'),
        array('3a','1b','2b','3a','4a','5b'),
        array('2a','1b','2a','3a','4a','10a'),
        array('2a','1b','2a','3a','4a','10a'),
        array('2a','1b','2a','3a','4a','10a'),
        array('1a','1a','2a','3a','9b','10a'),
        array('1a','1a','2a','3a','9b','10a')
        );

        for($i=0,$string3='';$i<=9;$i++)
        {  
        for($j=0,$sub_string3='';$j<=9;$j++)
        {

        if(in_array([$i+1,ceil(($j+1)/3)],$self_choose_session_site)){
        $sub_string3=$sub_string3."<td><u>".(string)$site_arr[$i][$j]."</u></td>";
        }else{
        $sub_string3=$sub_string3."<td>".(string)$site_arr[$i][$j]."</td>";
        }
        }
        $i_tmp=$i+1;
        $string3=$string3."<tr><th>$i_tmp</th>".$sub_string3."<tr>";
        }



        for($session=1,$string4='';$session<=10;$session++)
        {
        if($session==1){
        $round=1;
        $string4=$string4."<th rowspan='4' style='width:100px'>第"."$round"."轮</th>";
        }
        elseif($session==5){
        $round=2;
        $string4=$string4."<th rowspan='3' style='width:100px'>第"."$round"."轮</th>";
        }elseif($session==8){
        $round=3;
        $string4=$string4."<th rowspan='3' style='width:100px'>第"."$round"."轮</th>";
        }

        for($site=1;$site<=3;$site++)
        { 
        if($site==1){
        $judge_tmp=$judge_arr_A[$session-1];
        }elseif($site==2){
        $judge_tmp=$judge_arr_B[$session-1];
        }elseif($site==3){
        $judge_tmp=$judge_arr_C[$session-1];
        }

        for($judge=1;$judge<=5;$judge++)
        {
        if($judge_tmp[$judge]==$judge_tmp[0]){
        $string4=$string4."<td><strong>$judge_tmp[$judge]</strong></td>";
        }
        else{
        $string4=$string4."<td>$judge_tmp[$judge]</td>";
        }
        }
        //
        }
        $string4="<tr>".$string4."</tr>";
        }

        ?>
        <div class="alp-div">
            <div class="div1">
                <form action="lottery.php" name="lottery_input" method="post">
                    <div class="admin">
                        管理员邮箱<input type="email" class="form-control" required="required" id="email" name="email" placeholder="email" value="<?PHP echo $email;?>"/><br /> 
                        管理员密码<input type="password" class="form-control" required="required" id="password" name="password" placeholder="密码" /><br /> 
                    </div>
                    <table  border="1" cellspacing="0" class="table1">
                        <?PHP 
                        echo $string1;

                        echo $string2;
                        echo $string2_1;
                        echo $string2_2;

                        ?>
                    </table><br />
                    <span id='prompt'></span>
                    <div class="button-center">
                        <button id="lottery_submit" class="btn">抽签结果提交或修改</button>
                    </div>
                </form>
            </div>
            <script>
                window.onload = function () {
                    repeat();
                }

                function foo(str) {
                    for (i = 0; i < str.length; i++)
                    {
                        for (j = i + 1; j < str.length; j++)
                        {
                            if (str[i] == str[j]) {
                                return false
                            }
                        }
                    }
                    return true
                }

                function repeat() {
                    school_number = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
                    for (i = 1; i <= 10; i++) {
                        school_number[i - 1] = document.getElementById("school_number_" + i).value;
                    }
                    repeated = foo(school_number);
                    document.getElementById("lottery_submit").disabled = !repeated;
                    if (repeated) {
                        document.getElementById("prompt").innerHTML = "<font color='green'>抽签结果无重复，可录入</font>"
                    } else {
                        document.getElementById("prompt").innerHTML = "<font color='red'>抽签结果有重复，请检查后再录入</font>"
                    }
                }
            </script>

            <div class="parent">
                <div class="div2">
                    <table class="table2" border="1"  cellspacing="0">
                        <tr>
                            <th rowspan="2">场次</th>
                            <th colspan="3">场地1队伍</th>
                            <th colspan="3">场地2队伍</th>
                            <th colspan="3">场地3队伍</th>
                            <th colspan="1">轮空队伍</th>
                        </tr>
                        <tr>

                            <th >正</th>
                            <th >反</th>
                            <th >评</th>
                            <th >正</th>
                            <th >反</th>
                            <th >评</th>
                            <th >正</th>
                            <th >反</th>
                            <th >评</th>
                            <th >观</th>
                        </tr>
                        <?PHP
                        echo "$string3"; 
                        ?>
                    </table>
                </div>

                <div class="div3">
                    <table class="table3" border="1"  cellspacing="0">
                        <tr>
                            <th rowspan="7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
                            <th colspan="5" rowspan="1">场地1评委</th>
                            <th colspan="5" rowspan="1">场地2评委</th>
                            <th colspan="5" rowspan="1">场地3评委</th>
                        </tr>

                        <?PHP
                        echo "$string4"; 
                        ?>
                    </table>
                </div>
            </div>
        </div>
    </body>
</html>
